﻿/********************************************************************************
 * Developed by Phil Tyler (http://www.laidbackcoder.co.uk)
 * 
 * Cryptosolic is Licensed under the GNU Lesser General Public License (LGPL)
 * http://cryptosolic.codeplex.com/license
 * *****************************************************************************/
using System;
using System.Security.Cryptography;
using Cryptosolic.Security.Hashing;

namespace Cryptosolic.Security.Encryption.Symmetric
{
    /// <summary>
    /// DES Encryption Implementation
    /// </summary>
    /// <remarks>
    /// WARNING: DES is now widely considered to be insecure due to its small (56 bit) key size
    /// please consider using a stronger Cipher
    /// </remarks>
    [Obsolete("WARNING: DES is widely considered to be insecure due to its small (56 bit) key size, please consider using a stronger Cipher")]
    public class Des : SscSymmetricAlgorithm
    {
        private IHashingAlgorithm hashAlg;
		private SymmetricAlgorithm encrtypAlg;
		
		/// <summary>
		/// Hashing Algorithm
		/// </summary>
		public override IHashingAlgorithm HashingAlg
		{
			get 
			{
				if(hashAlg == null)
				{
					hashAlg = new Hashing.Sha1();
				}
				return hashAlg;
			}
		}
		
		/// <summary>
		/// Encryption Algorithm
		/// </summary>
		internal override SymmetricAlgorithm EncryptionAlg 
		{
			get 
			{
				if(encrtypAlg == null)
				{
					encrtypAlg = new DESCryptoServiceProvider();
				}
				return encrtypAlg;
			}
		}
    	
    	/// <summary>
		/// Key Size of Cipher (in bits)
		/// </summary>
		public override int KeySize
		{
			get { return 64; } //Only 56 Bits are used
		}
		
		/// <summary>
		/// Block Size of Cipher (in bits)
		/// </summary>
		public override int BlockSize 
		{
			get { return 64; }
		}	
		
		/// <summary>
        /// Method for Padding Cipher Text
        /// </summary>
		public override BytePaddingMode Padding 
		{
			get { return BytePaddingMode.PKCS7; }
		}
		
		/// <summary>
        /// Method used for Undertaking Encryption/Decryption
        /// </summary>
		public override BlockCipherMode Mode 
		{
			get { return BlockCipherMode.CBC; }
		}
    }
}
